package com.example.addwater.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @author ChumML created by 2020/12/02 8:55
 */
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@Setter
@Getter
public class Response<T> {

    private static final long serialVersionUID = 1L;
    private static final int RESPONSE_SUCCESS_CODE = 200;
    private static final int RESPONSE_FAIL_CODE = 200;
    @ApiModelProperty(value = "结果状态", example = "RESPONSE_SUCCESS_CODE")
    private Integer code = RESPONSE_SUCCESS_CODE;
    @ApiModelProperty(value = "结果数据")
    private T data;
    @ApiModelProperty(value = "结果描述", example = "成功")
    private String message = "success";

    public Response() {
    }

    public Response(Integer code) {
        this ();
        this.code = code;
    }

    public Response(Integer code, T data) {
        this ( code );
        this.data = data;
    }

    public Response(Integer code, String message) {
        this ( code );
        this.message = message;
    }

    public Response(Integer code, String message, T data) {
        this ( code, message );
        this.data = data;
    }

    public static <T> Response<T> success() {
        return new Response<> ( RESPONSE_SUCCESS_CODE );
    }

    public static <T> Response<T> success(T data) {
        return new Response<> ( RESPONSE_SUCCESS_CODE, data );
    }

    public static <T> Response<T> success(String message) {
        return new Response<> ( RESPONSE_SUCCESS_CODE, message );
    }

    public static <T> Response<T> success(String message, T data) {
        return new Response<> ( RESPONSE_SUCCESS_CODE, message, data );
    }

    public static <T> Response<T> success(Integer code, String message) {
        return new Response<> ( code, message );
    }

    public static <T> Response<T> success(Integer code, String message, T data) {
        return new Response<> ( code, message, data );
    }

    public static <T> Response<T> error() {
        return new Response<> ( RESPONSE_FAIL_CODE );
    }

    public static <T> Response<T> error(String message) {
        return new Response<> ( RESPONSE_FAIL_CODE, message );
    }

    public static <T> Response<T> error(T data) {
        return new Response<> ( RESPONSE_FAIL_CODE, data );
    }

    public static <T> Response<T> error(Integer code, String message) {
        return new Response<> ( code, message );
    }

    public static <T> Response<T> error(String message, T data) {
        return new Response<> ( RESPONSE_SUCCESS_CODE, message, data );
    }

}
